package com.example.practice.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.practice.R;
import com.example.practice.utils.SharedpreferencesUtils;

public class settingActivity_yl extends AppCompatActivity {
    private TextView tv_title;
    private TextView tv_back;
    private RelativeLayout rl_title_bar;
    private RelativeLayout rl_edit_pwd_yl,rl_edit_setting_security_yl,rl_logout_yl;
    public static settingActivity_yl instance =null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting_yl);

        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        instance=this;
        initView();

    }

    private void initView() {
        tv_title=findViewById(R.id.tv_title);
        tv_title.setText("设置");
        tv_back=findViewById(R.id.tv_back);
        rl_title_bar=findViewById(R.id.rl_bar);
        rl_title_bar.setBackgroundColor(Color.parseColor("#60b4f9"));
        rl_edit_pwd_yl=findViewById(R.id.rl_edit_pwd_yl);
        rl_edit_setting_security_yl=findViewById(R.id.rl_setting_security_yl);
        rl_logout_yl=findViewById(R.id.rl_logout_yl);

        tv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                settingActivity_yl.this.finish();
            }
        });

        rl_edit_pwd_yl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(settingActivity_yl.this,editPasswordActivity.class);
                startActivity(intent);
            }
        });

        rl_edit_setting_security_yl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(settingActivity_yl.this, securitySettingActivity.class);
                startActivity(intent);
            }
        });

        rl_logout_yl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(settingActivity_yl.this,"退出登陆成功",Toast.LENGTH_SHORT).show();
                clearLoginStatus();

                Intent data=new Intent();
                data.putExtra("isLogin",false);
                setResult(RESULT_OK,data);
                settingActivity_yl.this.finish();
            }
        });
    }
    /**
     * 清除SP中的登陆状态和登陆时的用户名
     */
    private void clearLoginStatus(){
        SharedPreferences sp=getSharedPreferences("loginInfo", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor= sp.edit();

        editor.putBoolean("isLogin", false);
        editor.putString("loginUserName", "");
        editor.commit();
    }
}